import pymysql
import uuid
import datetime


def save_userrole():
    db = pymysql.connect(host="192.168.0.188", user="pro", password="123456", database="gxzlk", port=3306)
    cursor = db.cursor()
    cursor.execute("SELECT * FROM user where email like '%_test@ourchem.com%' and userno > 11501 ORDER BY userno desc")
    data = cursor.fetchmany(40000)

    sql = "INSERT INTO user_userrole(id, user_id, user_role_id, create_time) " \
          "           VALUES (%s, %s,%s,%s) "
    ages = []
    for each in data:
        tmp = (str(uuid.uuid4()), each[0], '5eabf390-908a-4cd4-ad11-61851446e94d', datetime.datetime.now())
        ages.append(tmp)
    cursor.executemany(sql, ages)
    db.commit()


def save_user():
    db = pymysql.connect(host="192.168.0.188", user="pro", password="123456", database="gxzlk", port=3306)
    cursor = db.cursor()
    cursor.execute("SELECT * FROM user where email like '%qian%'")
    data = cursor.fetchone()

    sql = "INSERT INTO user(id, code, userno, name, real_name, email, sex, principal, " \
          "                 credentials, status, phoneno, description, salt, effective_date," \
          "                  expired_date, regdate, grade_id, regip, version, date_number, role, " \
          "                  expired_config, dept_id) " \
          "VALUES (%s, %s, %s, %s, %s, %s, %s, %s, " \
          "        %s, %s, %s, %s, %s, %s, " \
          "        %s, %s, %s, %s, %s, %s, %s, " \
          " %s, %s);"
    ages = []
    for i in range(11501, 41501):
        tmp = (str(uuid.uuid4()), data[1], i, data[3]+str(i), str(i) + data[4], str(i) + "_test@ourchem.com", data[6], data[7],
               data[8], data[9], data[10], data[11], data[12], data[13],
               data[14], data[15], data[16], data[17], data[18], data[19], data[20],
               data[21], data[22])
        ages.append(tmp)
    cursor.executemany(sql, ages)
    db.commit()


save_userrole()